package com.ghostbusters.fingertrack.control;

import com.ghostbusters.fingertrack.application.Mouse;
import com.ghostbusters.fingertrack.calibration.Calibration;
import com.ghostbusters.fingertrack.match.ApplicationMatcher;
import com.ghostbusters.fingertrack.wii.WiiMain;

public class ApplicationControl<E> {
	
	private Calibration<E> calibration;
	private ApplicationMatcher<E> matcher;
	private Mouse mouse;
	
	public static void main(String[] args) {
		Calibration<Character> calibration = new Calibration<Character>();
		
		// initiated up top
		ApplicationControl control = new ApplicationControl(calibration);
		
		
		// after "start browsing mode"
		control.startApplication();
		
		// after "end browsing mode"
		control.endApplication();
	}
	
	public ApplicationControl(Calibration<E> calibration) {
		setCalibration(calibration);
	}
	
	public void startApplication() {
		setMatcher(new ApplicationMatcher<E>(getCalibration()));
		try {
			mouse = new Mouse();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void endApplication() {
		try {
			WiiMain.unsubscribe(mouse);
			getApplicationMatcher().end();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void setCalibration(Calibration<E> calibration) {
		this.calibration = calibration;
	}

	public Calibration<E> getCalibration() {
		return calibration;
	}

	public void setMatcher(ApplicationMatcher<E> matcher) {
		this.matcher = matcher;
	}

	public ApplicationMatcher<E> getApplicationMatcher() {
		return matcher;
	}
}
